package com.ccrfid.rmc6.resource.video;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.video.VideoOrgEntity;
import com.ccrfid.rmc6.service.video.VideoOrgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Path("/video/orgs")
@Produces(MediaType.APPLICATION_JSON)
public class VideoOrgResource {
    private static final Logger logger = LoggerFactory.getLogger(VideoOrgResource.class);
    @Autowired
    private VideoOrgService videoOrgService;

    @GET
    public List<VideoOrgEntity> getVideoOrgList() {
        List<VideoOrgEntity> list = videoOrgService.getVideoOrgList();
        return list;
    }

    @GET
    @Path("{orgSn}")
    public VideoOrgEntity getVideoOrgInfo(@PathParam("orgSn") String orgSn) {
        VideoOrgEntity videoOrgEntity = videoOrgService.getVideoOrgBySn(orgSn);
        return videoOrgEntity;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public VideoOrgEntity createVideoOrg(VideoOrgEntity entity) throws AppException {
        VideoOrgEntity videoOrgEntity = videoOrgService.createVideoOrg(entity);
        return videoOrgEntity;
    }

    @PUT
    @Path("{orgSn}")
    @Consumes(MediaType.APPLICATION_JSON)
    public VideoOrgEntity updateVideoOrg(@PathParam("orgSn") String orgSn, VideoOrgEntity entity) throws AppException {
        VideoOrgEntity videoOrgEntity = videoOrgService.updateVideoOrg(orgSn, entity);
        return videoOrgEntity;
    }

    @DELETE
    @Path("{orgSn}")
    public Boolean deleteVideoOrg(@PathParam("orgSn") String orgSn) throws AppException {
        return videoOrgService.deleteVideoOrg(orgSn);
    }

    @GET
    @Path("{orgSn}/subs")
    public List<VideoOrgEntity> getSubVideoOrgList(@PathParam("orgSn") String orgSn) {
        List<VideoOrgEntity> list = videoOrgService.getSubVideoOrgList(orgSn);
        return list;
    }

    @PUT
    @Path("{orgSn}/sync-org")
    public Boolean syncVideoOrgNode(@PathParam("orgSn") String orgSn) throws AppException {
        return videoOrgService.syncVideoOrgNode(orgSn);
    }
}
